
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import uView from '@/uni_modules/uview-ui'
import validator from '@/utils/validator.js'
import request from '@/utils/request.js'
import config from '@/utils/config.js'
import utils from '@/utils/util.js'
import store from '@/store/index.js'
import enums from '@/utils/enums.js'
import AesUtil from '@/utils/AesUtil.js'

Vue.config.productionTip = false

Vue.use(uView)

Vue.prototype.$request = request
Vue.prototype.$FILE_URL = config.fileUrl
Vue.prototype.enums = enums

uni.validator = validator
uni.utils = utils
uni.store = store
uni.config = config

uni.$store = {
	/**
	 * 缓存数据
	 * @param key 字段名称
	 * @param data 数据
	 */
	set: (key, data, sync = false) => {
		if(sync) {
			uni.setStorageSync(key, AesUtil.encrypt(data))
		}else {
			uni.setStorage({
				key: key,
				data: AesUtil.encrypt(data)
			})
		}
	},
	/**
	 * 获取数据缓存
	 * @param key 字段名称
	 */
	get: (key) => {
		return AesUtil.decrypt(uni.getStorageSync(key))
	}
}

uni.toast = {
	/**
	 * @param title 提示内容
	 * @param icon 图标
	 * @param mask 蒙层
	 * @param duration 持续时长
	 */
	show: ({ title, icon = 'none', mask = false, duration = 2000 }) => {
		uni.showToast({
			title: title,
			icon: icon,
			mask: mask,
			duration: duration
		})
	},
	hide: () => {
		uni.hideToast()
	}
}

uni.loading = {
	/**
	 * @param title 提示文字
	 * @param mask 蒙层
	 */
	show: (title = '加载中', mask = true) => {
		uni.showLoading({
			title: title,
			mask: mask
		})
	},
	hide: () => {
		uni.hideLoading()
	}
}

uni.modal = ({
	showCancel = false,
	confirmText = '确定',
	cancelText = '取消',
	title = '系统提示',
	content = ''
}) => {
	return new Promise((resolve, reject) => {
		uni.showModal({
			showCancel: showCancel,
			cancelText: cancelText,
			confirmText: confirmText,
			title: title,
			content: content,
			success: (rs) => {
				if(rs.confirm) {
					resolve()
				}else {
					reject()
				}
			}
		})
	})
}

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif